﻿using DivisonsCodeTools.Business;
using DivisonsCodeTools.Business.Configure;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DivisonsCodeTools.Frm
{
    public partial class FrmTools : Form
    {
        public FrmTools()
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            InitializeComponent();
        }

        private void FrmTools_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Config.GetInstance().FileName))
                this.Tbx_FileName.Text = Config.GetInstance().FileName;
            if (!string.IsNullOrEmpty(Config.GetInstance().FilePath))
                this.Tbx_FilePath.Text = Config.GetInstance().FilePath;
            if (!string.IsNullOrEmpty(Config.GetInstance().Url))
                this.Tbx_Url.Text = Config.GetInstance().Url;
        }

        private void Btn_Save_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.Tbx_FileName.Text))
                Config.GetInstance().FileName = this.Tbx_FileName.Text.Trim();
            if (!string.IsNullOrEmpty(this.Tbx_FilePath.Text))
                Config.GetInstance().FilePath = this.Tbx_FilePath.Text.Trim();
            if (!string.IsNullOrEmpty(this.Tbx_Url.Text))
                Config.GetInstance().Url = this.Tbx_Url.Text.Trim();
            AppConfig.Save(Config.GetInstance());
            MessageBox.Show("保存成功！");
            this.Close();
        }

        private void Tbx_FilePath_MouseClick(object sender, MouseEventArgs e)
        {
            this.folderBrowserDialog1.Description = "选择导出的文件路径";
            this.folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
            if (this.folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Config.GetInstance().FilePath = this.folderBrowserDialog1.SelectedPath;
                this.Tbx_FilePath.Text = Config.GetInstance().FilePath;
            }
        }
    }
}
